﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using EzDesk.Utility.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace EzDesk.Utility.Web.Extensions
{
    public static class WebJsonExtension
    {
        public static string ToJson(this object obj)
        {
            var result = JsonConvert.SerializeObject(
                obj,
                new StringEnumConverter(), new EpochDateTimeConverter()
                );

            return result;
        }

        public static T FromJson<T>(string jsonStr)
        {
            return (T)JsonConvert.DeserializeObject(
                jsonStr,
                typeof(T),
                new StringEnumConverter(), new EpochDateTimeConverter()
                );
        }
    }
}
